package business.impl;

import java.util.List;

import model.TStuinfo;
import model.VStuinfo;
import model.VWanted;
import business.basic.iHibBaseDAO;
import business.basic.iHibBaseDAOImpl;
import business.dao.StuDao;

public class SruDaoIpml implements StuDao {
	
	iHibBaseDAO bdao = null;
	public void setBdao (iHibBaseDAO bdao){
		this.bdao=bdao;
		
	}
	@Override
	public TStuinfo getstuById(int id) {
		TStuinfo title = (TStuinfo) bdao.findById(TStuinfo.class,id);
		return title;
	}

	@Override
	public int addstu(TStuinfo model) {
		Object obj = bdao.insert(model);
		if (obj == null) {
			return 0;
		}
		return 1;
	}

	@Override
	public boolean upstu(TStuinfo model) {
		return bdao.update(model);
	}

	@Override
	public boolean delstu(int id) {
		return bdao.delete(TStuinfo.class, id);
	}

	@Override
	public List<VStuinfo> getstulistbyma(String majorname) {
		String sql = " from VStuinfo where  majorname  like '%"+majorname+"%' order by  completiondegree desc";
	
		List<VStuinfo> modl = bdao.select(sql);
		return modl;
	}

	@Override
	public List<VStuinfo> getstulistbyclass(String classid) {
		String sql = " from VStuinfo where  classname  = ? order by  completiondegree desc ";
		Object[] para = {classid};
		List<VStuinfo> modl =  bdao.select(sql, para);
		return modl;
	}

	@Override
	public VStuinfo getstuByuserId(int id) {
		String sql = " from VStuinfo  where userid= ?  ";
		Object[] para = {id};
		VStuinfo modl = (VStuinfo) bdao.selectby(sql, para);
		return modl;
	}
	
	@Override
	public String[] getStringbyid(int stuid) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public List<VStuinfo> getstulist() {
		String sql = " from VStuinfo ";
		List<VStuinfo> modl =  bdao.select(sql);
		return modl;
	}
	@Override
	public VStuinfo getstulistbyid(int stuid) {
		VStuinfo title = (VStuinfo) bdao.findById(VStuinfo.class,stuid);
		return title;
	}
	
	@Override
	public List<VStuinfo> getVStuinfobypost(String search) {
		String sql = "  from VStuinfo ";
				sql+= "  where isDel = 0 ";
				
				
				sql+= " and  stuname like '%"+search+"%'";
				sql+= " or school like '%"+search+"%'" ;
				sql+= " or majorname like '%"+search+"%'" ;
				sql+= " or classname like '%"+search+"%'" ;
				sql+= " or college like '%"+search+"%'" ;
				
				sql	+= "order by  completiondegree desc ";

				List<VStuinfo> modl = bdao.select(sql);
				return modl;	
	}

}
